import { IMessageHandle, IMessageStruct } from './messageHandleManager';
import { SoldOutMessageHandle } from "./messageHandle";
export class InnerMessageHandleManager {
    static Current: InnerMessageHandleManager = new InnerMessageHandleManager();
    private handleList: IMessageHandle[] = [];
    constructor() {

    }
    /**
     * 注册消息处理器
     * @param  {IMessageHandle} handle
     */
    RegistMessageHandle() {
        this.handleList.push(new SoldOutMessageHandle())
    }
    /**
     * 获取消息处理器
     * @param  {string} name 处理器名称
     * @returns T
     */
    GetMessageHanle<T>(handleName: string): T {
        let handleItem = this.handleList.find(x => x.HandleName == handleName);
        return handleItem as any;
    }

    /**
     * 接收底层消息
     * @param  {IMessageStruct} msg
     */
    ReceivedMessage(msg: IMessageStruct) {
        let handleItem = this.handleList.find(x => x.MessageName == msg.headers.name);
        if (handleItem) {
            handleItem.OnReceived(handleItem, msg);
        }
    }
}
